// JavaScript Document for HighCharts Creation
	
	var serverUrl = 'http://haas.uwf.edu:20000/test/WebForm1.aspx?';
	var chart;	
//	END GLOBAL VARIABLES

/*
	Script Locations:
	
	-Nation:		40
	-Florida:		211
	
	-Crestview:		279
	-Panama City:	319
	-Pensacola:		359
	-Tallahassee:	399
	
	-Daytona Beach:	426
	-Gainesville:	453
	-Jacksonville:	480
	-Ocala:			507
	-Palm Coast:	534
	
	-Orlando:		561
	-Palm Bay:		588
	-Tampa:			615
	-Winter Haven:	642
	-Vero Beach:	669
	
	-Fort Myers:	696
	-Miami:			723
	-Naples:		750
	-Port St Lucie:	777
	-Punta Gorda:	804
	-Sarasota:		831
*/

/////////++++++++++++++++++++/////////NATION////////++++++++++++++++++++//////////

///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#NationEmploymentCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationEmploymentCharts', '#nation', 'Aaron, please find time to get me some content!  I look empty withouth it; cant you see?');
});
$( "#NationEmploymentCharts" ).on( "pagebeforeshow", function( event ) {
	//generateContainer('#NationEmploymentCharts');
});
$(document).on('pageshow', '#NationEmploymentCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=employment', 'United States Employment (SA)', 'Employment', 'US Employment', 'nationEmploymentCharts_container');
});
$( "#NationEmploymentCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationEmploymentCharts');
});
///////////////////////////////////// UNEMPLOYMENT /////////////////////////////////////////
$( "#NationUnemploymentCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationUnemploymentCharts', '#nation');
});
$( "#NationUnemploymentCharts" ).on( "pagebeforeshow", function( event ) {
	//generateContainer('#NationUnemploymentCharts');
});
$(document).on('pageshow', '#NationUnemploymentCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=unemployment_rate', 'United States Unemployment Rate', 'Percent', 'US Unemployment', 'nationUnemploymentCharts_container');
});
$( "#NationUnemploymentCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationUnemploymentCharts');
});
///////////////////////////////////// INFLATION - CONSUMER PRICE INDEX /////////////////////////////////////////
$( "#NationInflationCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationInflationCharts', '#nation');
});
$( "#NationInflationCharts" ).on( "pagebeforeshow", function( event ) {
	//generateContainer('#NationInflationCharts');
});
$(document).on('pageshow', '#NationInflationCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=inflation_or_cpi', 'United States Consumer Price Index', 'Index', 'US Inflation', 'nationInflationCharts_container');
});
$( "#NationInflationCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationInflationCharts');
});
///////////////////////////////////// GDP UPDATED QUARTERLY /////////////////////////////////////////
$( "#NationGDPCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationGDPCharts', '#nation');
});
$( "#NationGDPCharts" ).on( "pagebeforeshow", function( event ) {
	//generateContainer('#NationGDPCharts');
});
$(document).on('pageshow', '#NationGDPCharts', function(){  
	generateCharts(serverUrl + 'table=nationquarterly&column=gross_domestic_product', 'United States Gross Domestic Product', '$USD', 'GDP', 'nationGDPCharts_container', 'quarterly');
});
$( "#NationGDPCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationGDPCharts');
});
///////////////////////////////////// CONSUMER CONFICENCE /////////////////////////////////////////
$( "#NationConsumerConfidenceCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationConsumerConfidenceCharts', '#nation');
});
$( "#NationConsumerConfidenceCharts" ).on( "pagebeforeshow", function( event ) {
	//generateContainer('#NationConsumerConfidenceCharts');
});
$(document).on('pageshow', '#NationConsumerConfidenceCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=consumer_confidence_index', 'United States Consumer Confidence', '???', 'Consumer Confidence', 'nationConsumerConfidenceCharts_container');
});
$( "#NationConsumerConfidenceCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationConsumerConfidenceCharts');
});
///////////////////////////////////// CASE SHILLER INDEX /////////////////////////////////////////
$( "#NationCaseShillerCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationCaseShillerCharts', '#nation');
});
$( "#NationCaseShillerCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationCaseShillerCharts');
});
$(document).on('pageshow', '#NationCaseShillerCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=case_shiller_home_price_index', 'United States Case Shiller Index (SA)', 'Index', 'CS Index', 'nationCaseShillerCharts_container');
});
$( "#NationCaseShillerCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationCaseShillerCharts');
});
///////////////////////////////////// MORTGAGE RATES - MORTGAGE MARKET SURVEY /////////////////////////////////////////
$( "#NationRatesCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationRatesCharts', '#nation');
});
$( "#NationRatesCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationRatesCharts');
});
$(document).on('pageshow', '#NationRatesCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=mortgage_market_survey', '30 Yr Fixed Mortgage Rate', 'Rate', 'Mortgage Rates', 'nationRatesCharts_container');
});
$( "#NationRatesCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationRatesCharts');
});
///////////////////////////////////// HOUSING PERMITS - RESIDENTIAL PERMITS /////////////////////////////////////////
$( "#NationPermitsCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationPermitsCharts', '#nation');
});
$( "#NationPermitsCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationPermitsCharts');
});
$(document).on('pageshow', '#NationPermitsCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=residential_permits', 'United States Housing Permits', 'Permits', 'Housing Permits', 'nationPermitsCharts_container');
});
$( "#NationPermitsCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationPermitsCharts');
});
///////////////////////////////////// CRUDE OIL /////////////////////////////////////////
$( "#NationCrudeOilCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationCrudeOilCharts', '#nation');
});
$( "#NationCrudeOilCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationCrudeOilCharts');
});
$(document).on('pageshow', '#NationCrudeOilCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=oil_price', 'US Crude Oil ???', '???', 'Crude Oil', 'nationCrudeOilCharts_container');
});
$( "#NationCrudeOilCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationCrudeOilCharts');
});
///////////////////////////////////// GAS /////////////////////////////////////////
$( "#NationGasCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationGasCharts', '#nation');
});
$( "#NationGasCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationGasCharts');
});
$(document).on('pageshow', '#NationGasCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=unleaded_gasoline', 'US All Grades Retail Gasoline Price', 'Price', 'Gas', 'nationGasCharts_container');
});
$( "#NationGasCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationGasCharts');
});
///////////////////////////////////// GOLD /////////////////////////////////////////
$( "#NationGoldCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationGoldCharts', '#nation');
});
$( "#NationGoldCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationGoldCharts');
});
$(document).on('pageshow', '#NationGoldCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=gold_price', 'US Gold ???', '???', 'Gold', 'nationGoldCharts_container');
});
$( "#NationGoldCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationGoldCharts');
});
///////////////////////////////////// 10 YEAR TREASURY /////////////////////////////////////////
$( "#Nation10YearTreasuryCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#Nation10YearTreasuryCharts', '#nation');
});
$( "#Nation10YearTreasuryCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#Nation10YearTreasuryCharts');
});
$(document).on('pageshow', '#Nation10YearTreasuryCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=ten_year_treasury', '10 Year Treasury ???', '???', '10 Year Treasury', 'nation10YearTreasuryCharts_container');
});
$( "#Nation10YearTreasuryCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#Nation10YearTreasuryCharts');
});
///////////////////////////////////// US DOLLAR INDEX - US DOLLAR EXCHANGE RATE /////////////////////////////////////////
$( "#NationUSDollarIndexCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NationUSDollarIndexCharts', '#nation');
});
$( "#NationUSDollarIndexCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NationUSDollarIndexCharts');
});
$(document).on('pageshow', '#NationUSDollarIndexCharts', function(){  
	generateCharts(serverUrl + 'table=nationmonthly&column=us_dollar_exchange_rate', 'US Dollar Index ???', '???', 'US Dollar Index', 'nationUSDollarIndexCharts_container');
});
$( "#NationUSDollarIndexCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#NationUSDollarIndexCharts');
});
///////////////End of Nation///////////////

/////////++++++++++++++++++++///////// FLORIDA ////////++++++++++++++++++++//////////

///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#FloridaEmploymentCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FloridaEmploymentCharts', '#florida');
});
$( "#FloridaEmploymentCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FloridaEmploymentCharts');
});
$(document).on('pageshow', '#FloridaEmploymentCharts', function(){  
	generateCharts(serverUrl + 'table=floridadata&column=employment', 'Florida Employment', 'Employment', 'FL Employment', 'floridaEmploymentCharts_container');
});
$( "#FloridaEmploymentCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#FloridaEmploymentCharts');
});
///////////////////////////////////// UNEMPLOYMENT /////////////////////////////////////////  !!! May need to add US rate !!!
$( "#FloridaUnemploymentCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FloridaUnemploymentCharts', '#florida');
});
$( "#FloridaUnemploymentCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FloridaUnemploymentCharts');
});
$(document).on('pageshow', '#FloridaUnemploymentCharts', function(){  
	generateCharts(serverUrl + 'table=floridadata&column=unemployment_rate', 'Florida Unemployment Rate', 'Percent', 'FL Unemployment', 'floridaUnemploymentCharts_container');
});
$( "#FloridaUnemploymentCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#FloridaUnemploymentCharts');
});
///////////////////////////////////// FREDDIE MAC HOUSE PRICE INDEX /////////////////////////////////////////
$( "#FloridaFreddieMacHousePriceIndexCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FloridaFreddieMacHousePriceIndexCharts', '#florida');
});
$( "#FloridaFreddieMacHousePriceIndexCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FloridaFreddieMacHousePriceIndexCharts');
});
$(document).on('pageshow', '#FloridaFreddieMacHousePriceIndexCharts', function(){  
	generateCharts(serverUrl + 'table=floridadata&column=freddie_mac_house_price_index', 'Freddie Mac House Price Index ???', 'Aaron, where is the data???', 'Freddie Mac Price Index', 'floridaFreddieMacHousePriceIndexCharts_container');
});
$( "#FloridaFreddieMacHousePriceIndexCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#FloridaFreddieMacHousePriceIndexCharts');
});
///////////////////////////////////// CONSUMER CONFIDENCE INDEX /////////////////////////////////////////
$( "#FloridaConsumerConfidenceIndexCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FloridaConsumerConfidenceIndexCharts', '#florida');
});
$( "#FloridaConsumerConfidenceIndexCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FloridaConsumerConfidenceIndexCharts');
});
$(document).on('pageshow', '#FloridaConsumerConfidenceIndexCharts', function(){  
	generateCharts(serverUrl + 'table=floridadata&column=consumer_confidence_index', 'Consumer Confidence Index ???', '???', 'Consumer Confidence Index', 'floridaConsumerConfidenceIndexCharts_container');
});
$( "#FloridaConsumerConfidenceIndexCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#FloridaConsumerConfidenceIndexCharts');
});
///////////////////////////////////// UNLEADED GASOLINE PRICES /////////////////////////////////////////
$( "#FloridaUnleadedGasolinePricesCharts" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FloridaUnleadedGasolinePricesCharts', '#florida');
});
$( "#FloridaUnleadedGasolinePricesCharts" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FloridaUnleadedGasolinePricesCharts');
});
$(document).on('pageshow', '#FloridaUnleadedGasolinePricesCharts', function(){  
	generateCharts(serverUrl + 'table=floridadata&column=unleaded_gasoline_price', 'Florida All Grades Gasoline Price', 'Price', 'FL Unleaded Gas Prices', 'floridaUnleadedGasolinePricesCharts_container');
});
$( "#FloridaUnleadedGasolinePricesCharts" ).on( "pagebeforehide", function( event ) {
	removeElements('#FloridaUnleadedGasolinePricesCharts');
});
///////////////End of Florida///////////////

/////////++++++++++++++++++++///////// FLORIDA MSA ////////++++++++++++++++++++//////////

//////////////////Crestview//////////////////

///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#CrestviewEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#CrestviewEmployment', '#crestview');
});
$( "#CrestviewEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#CrestviewEmployment');
});
$(document).on('pageshow', '#CrestviewEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'Employment Crestview MSA (NSA)', 'Employment ($USD)???', 'Crestview Employment');
});
$( "#CrestviewEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#CrestviewEmployment');
});
///////////////////////////////////// UNEMPLOYMENT RATE /////////////////////////////////////////
$( "#CrestviewUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#CrestviewUnemployment', '#crestview');
});
$( "#CrestviewUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#CrestviewUnemployment');
});
$(document).on('pageshow', '#CrestviewUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'Crestview MSA Unemployment Rate', 'Precent', 'Crestview Unemployment');
});
$( "#CrestviewUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#CrestviewUnemployment');
});
///////////////////////////////////// BED TAX /////////////////////////////////////////
$( "#CrestviewBedTax" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#CrestviewBedTax', '#crestview');
});
$( "#CrestviewBedTax" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#CrestviewBedTax');
});
$(document).on('pageshow', '#CrestviewBedTax', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'Crestview MSA Bed Tax ???', '???', 'Crestview Bed Tax');
});
$( "#CrestviewBedTax" ).on( "pagebeforehide", function( event ) {
	removeElements('#CrestviewBedTax');
});

//////////////////Panama City//////////////////
$( "#PanamaCityEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PanamaCityEmployment', '#panamaCity');
});
$( "#PanamaCityEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PanamaCityEmployment');
});
$(document).on('pageshow', '#PanamaCityEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PanamaCityEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PanamaCityEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PanamaCityUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PanamaCityUnemployment', '#panamaCity');
});
$( "#PanamaCityUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PanamaCityUnemployment');
});
$(document).on('pageshow', '#PanamaCityUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PanamaCityUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PanamaCityUnemployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PanamaCityBedTax" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PanamaCityBedTax', '#panamaCity');
});
$( "#PanamaCityBedTax" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PanamaCityBedTax');
});
$(document).on('pageshow', '#PanamaCityBedTax', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PanamaCityBedTax" ).on( "pagebeforehide", function( event ) {
	removeElements('#PanamaCityBedTax');
});

//////////////////Pensacola//////////////////
$( "#PensacolaEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PensacolaEmployment', '#pensacola');
});
$( "#PensacolaEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PensacolaEmployment');
});
$(document).on('pageshow', '#PensacolaEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PensacolaEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PensacolaEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PensacolaUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PensacolaUnemployment', '#pensacola');
});
$( "#PensacolaUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PensacolaUnemployment');
});
$(document).on('pageshow', '#PensacolaUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PensacolaUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PensacolaUnemployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PensacolaBedTax" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PensacolaBedTax', '#pensacola');
});
$( "#PensacolaBedTax" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PensacolaBedTax');
});
$(document).on('pageshow', '#PensacolaBedTax', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PensacolaBedTax" ).on( "pagebeforehide", function( event ) {
	removeElements('#PensacolaBedTax');
});

//////////////////Tallahassee//////////////////
$( "#TallahasseeEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#TallahasseeEmployment', '#tallahassee');
});
$( "#TallahasseeEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#TallahasseeEmployment');
});
$(document).on('pageshow', '#TallahasseeEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#TallahasseeEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#TallahasseeEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#TallahasseeUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#TallahasseeUnemployment', '#tallahassee');
});
$( "#TallahasseeUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#TallahasseeUnemployment');
});
$(document).on('pageshow', '#TallahasseeUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#TallahasseeUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#TallahasseeUnemployment');
});

//////////////////Daytona Beach//////////////////
$( "#DaytonaBeachEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#DaytonaBeachEmployment', '#daytonaBeach');
});
$( "#DaytonaBeachEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#DaytonaBeachEmployment');
});
$(document).on('pageshow', '#DaytonaBeachEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#DaytonaBeachEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#DaytonaBeachEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#DaytonaBeachUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#DaytonaBeachUnemployment', '#daytonaBeach');
});
$( "#DaytonaBeachUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#DaytonaBeachUnemployment');
});
$(document).on('pageshow', '#DaytonaBeachUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#DaytonaBeachUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#DaytonaBeachUnemployment');
});

//////////////////Gainesville//////////////////
$( "#GainesvilleEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#GainesvilleEmployment', '#gainesville');
});
$( "#GainesvilleEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#GainesvilleEmployment');
});
$(document).on('pageshow', '#GainesvilleEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#GainesvilleEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#GainesvilleEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#GainesvilleUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#GainesvilleUnemployment', '#gainesville');
});
$( "#GainesvilleUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#GainesvilleUnemployment');
});
$(document).on('pageshow', '#GainesvilleUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=escambia', 'Gainesville Unemployment', 'Unemployment Rate');
});
$( "#GainesvilleUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#GainesvilleUnemployment');
});

//////////////////Jacksonville//////////////////
$( "#JacksonvilleEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#JacksonvilleEmployment', '#jacksonville');
});
$( "#JacksonvilleEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#JacksonvilleEmployment');
});
$(document).on('pageshow', '#JacksonvilleEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#JacksonvilleEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#JacksonvilleEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#JacksonvilleUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#JacksonvilleUnemployment', '#jacksonville');
});
$( "#JacksonvilleUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#JacksonvilleUnemployment');
});
$(document).on('pageshow', '#JacksonvilleUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#JacksonvilleUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#JacksonvilleUnemployment');
});

//////////////////Ocala//////////////////
$( "#OcalaEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#OcalaEmployment', '#ocala');
});
$( "#OcalaEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#OcalaEmployment');
});
$(document).on('pageshow', '#OcalaEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#OcalaEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#OcalaEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#OcalaUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#OcalaUnemployment', '#ocala');
});
$( "#OcalaUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#OcalaUnemployment');
});
$(document).on('pageshow', '#OcalaUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#OcalaUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#OcalaUnemployment');
});

//////////////////Palm Coast//////////////////
$( "#PalmCoastEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PalmCoastEmployment', '#palmCoast');
});
$( "#PalmCoastEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PalmCoastEmployment');
});
$(document).on('pageshow', '#PalmCoastEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PalmCoastEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PalmCoastEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PalmCoastUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PalmCoastUnemployment', '#palmCoast');
});
$( "#PalmCoastUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PalmCoastUnemployment');
});
$(document).on('pageshow', '#PalmCoastUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PalmCoastUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PalmCoastUnemployment');
});

//////////////////Orlando//////////////////
$( "#OrlandoEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#OrlandoEmployment', '#orlando');
});
$( "#OrlandoEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#OrlandoEmployment');
});
$(document).on('pageshow', '#OrlandoEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#OrlandoEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#OrlandoEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#OrlandoUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#OrlandoUnemployment', '#orlando');
});
$( "#OrlandoUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#OrlandoUnemployment');
});
$(document).on('pageshow', '#OrlandoUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#OrlandoUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#OrlandoUnemployment');
});

//////////////////Palm Bay//////////////////
$( "#PalmBayEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PalmBayEmployment', '#palmBay');
});
$( "#PalmBayEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PalmBayEmployment');
});
$(document).on('pageshow', '#PalmBayEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PalmBayEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PalmBayEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PalmBayUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PalmBayUnemployment', '#palmBay');
});
$( "#PalmBayUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PalmBayUnemployment');
});
$(document).on('pageshow', '#PalmBayUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PalmBayUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PalmBayUnemployment');
});

//////////////////Tampa//////////////////
$( "#TampaEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#TampaEmployment', '#tampa');
});
$( "#TampaEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#TampaEmployment');
});
$(document).on('pageshow', '#TampaEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#TampaEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#TampaEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#TampaUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#TampaUnemployment', '#tampa');
});
$( "#TampaUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#TampaUnemployment');
});
$(document).on('pageshow', '#TampaUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#TampaUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#TampaUnemployment');
});

//////////////////Winter Haven//////////////////
$( "#WinterHavenEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#WinterHavenEmployment', '#winterHaven');
});
$( "#WinterHavenEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#WinterHavenEmployment');
});
$(document).on('pageshow', '#WinterHavenEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#WinterHavenEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#WinterHavenEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#WinterHavenUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#WinterHavenUnemployment', '#winterHaven');
});
$( "#WinterHavenUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#WinterHavenUnemployment');
});
$(document).on('pageshow', '#WinterHavenUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#WinterHavenUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#WinterHavenUnemployment');
});

//////////////////Vero Beach//////////////////
$( "#VeroBeachEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#VeroBeachEmployment', '#veroBeach');
});
$( "#VeroBeachEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#VeroBeachEmployment');
});
$(document).on('pageshow', '#VeroBeachEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#VeroBeachEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#VeroBeachEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#VeroBeachUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#VeroBeachUnemployment', '#veroBeach');
});
$( "#VeroBeachUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#VeroBeachUnemployment');
});
$(document).on('pageshow', '#VeroBeachUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#VeroBeachUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#VeroBeachUnemployment');
});

//////////////////Fort Myers//////////////////
$( "#FortMyersEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FortMyersEmployment', '#fortMyers');
});
$( "#FortMyersEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FortMyersEmployment');
});
$(document).on('pageshow', '#FortMyersEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#FortMyersEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#FortMyersEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#FortMyersUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#FortMyersUnemployment', '#fortMyers');
});
$( "#FortMyersUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#FortMyersUnemployment');
});
$(document).on('pageshow', '#FortMyersUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#FortMyersUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#FortMyersUnemployment');
});

//////////////////Miami//////////////////
$( "#MiamiEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#MiamiEmployment', '#miami');
});
$( "#MiamiEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#MiamiEmployment');
});
$(document).on('pageshow', '#MiamiEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#MiamiEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#MiamiEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#MiamiUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#MiamiUnemployment', '#miami');
});
$( "#MiamiUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#MiamiUnemployment');
});
$(document).on('pageshow', '#MiamiUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#MiamiUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#MiamiUnemployment');
});

//////////////////Naples//////////////////
$( "#NaplesEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NaplesEmployment', '#naples');
});
$( "#NaplesEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NaplesEmployment');
});
$(document).on('pageshow', '#NaplesEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#NaplesEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#NaplesEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#NaplesUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#NaplesUnemployment', '#naples');
});
$( "#NaplesUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#NaplesUnemployment');
});
$(document).on('pageshow', '#NaplesUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#NaplesUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#NaplesUnemployment');
});

//////////////////Port St. Lucie//////////////////
$( "#PortStLucieEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PortStLucieEmployment', '#portStLucie');
});
$( "#PortStLucieEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PortStLucieEmployment');
});
$(document).on('pageshow', '#PortStLucieEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PortStLucieEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PortStLucieEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PortStLucieUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PortStLucieUnemployment', '#portStLucie');
});
$( "#PortStLucieUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PortStLucieUnemployment');
});
$(document).on('pageshow', '#PortStLucieUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PortStLucieUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PortStLucieUnemployment');
});

//////////////////Punta Gorda//////////////////
$( "#PuntaGordaEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PuntaGordaEmployment', '#puntaGorda');
});
$( "#PuntaGordaEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PuntaGordaEmployment');
});
$(document).on('pageshow', '#PuntaGordaEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PuntaGordaEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PuntaGordaEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#PuntaGordaUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#PuntaGordaUnemployment', '#puntaGorda');
});
$( "#PuntaGordaUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#PuntaGordaUnemployment');
});
$(document).on('pageshow', '#PuntaGordaUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#PuntaGordaUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#PuntaGordaUnemployment');
});

//////////////////Sarasota//////////////////
$( "#SarasotaEmployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#SarasotaEmployment', '#sarasota');
});
$( "#SarasotaEmployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#SarasotaEmployment');
});
$(document).on('pageshow', '#SarasotaEmployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#SarasotaEmployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#SarasotaEmployment');
});
///////////////////////////////////// EMPLOYMENT /////////////////////////////////////////
$( "#SarasotaUnemployment" ).on( "pagebeforecreate", function( event ) {
	generateFooter('#SarasotaUnemployment', '#sarasota');
});
$( "#SarasotaUnemployment" ).on( "pagebeforeshow", function( event ) {
	generateContainer('#SarasotaUnemployment');
});
$(document).on('pageshow', '#SarasotaUnemployment', function(){  
	generateCharts(serverUrl + 'table=countyunemployment&column=franklin', 'National Unemployment', 'Unemployment Rate');
});
$( "#SarasotaUnemployment" ).on( "pagebeforehide", function( event ) {
	removeElements('#SarasotaUnemployment');
});






//////////////GENERAL FUNCTIONS//////////////

function generateFooter(page, backBrowse, infoMessage)
{
	console.log(page+": inserting footer");
	var htmlElements = "\
        <div data-role=\"popup\" id=\"button3\" class=\"ui-content\" style=\"max-width:280px\">\
        	<a href=\"#\" data-rel=\"back\" data-role=\"button\" data-theme=\"a\" data-icon=\"delete\" data-iconpos=\"notext\" class=\"ui-btn-right\" >close</a>\
            <p>"+infoMessage+"</p>\
        </div>\
   <div data-role=\"footer\" style=\"overflow:hidden\" data-position=\"fixed\" data-tap-toggle=\"false\">\
        	<div data-role=\"navbar\">\
            	<ul>\
                	<li><a href=\""+backBrowse+"\"><i class=\"icon-reply\"></i></a></li>\
                	<li><a href=\"#\" id='byr1' >1 yr</a></li>\
                    <li><a href=\"#\" id='byr5' >5 yr</a></li>\
                    <li><a href=\"#\" id='byr10' class=\"ui-btn-active ui-state-presist\">10 yr</a></li>\
                    <li><a href=\"#button3\" data-rel=\"popup\" data-position-to=\"window\"><i class=\"icon-info\"></i></a></li>\
            	</ul>\
        	</div>\
    </div>";
	
	$(page).append(htmlElements);
	console.log(page+": footer inserted");
}

function generateContainer(page)
{
	console.log(page+": inserting container");
	var htmlElements = "<div id=\"container\" class=\"myChart\"></div>";
	
	$(page).append(htmlElements);
	console.log(page+": container inserted");
}


function generateCharts(url, title, yAxisTitle, toolTitle, container, density)//Density used by Nation GDP only
{	
	var globalData = "No-Data~101";
	
	//Get the data for this section
	console.log(title+": getting data");
	globalData = getData(url);
	console.log(title+": data obtained");
	
	var stepSize = determineStepSize(density, 10);
	var chartLength = determineChartLength(density, 10);
	
	//Draw an initial chart
	console.log(title+": drawing initial chart into "+container);
	drawChart(container, title, yAxisTitle, stepSize, chartLength, toolTitle, globalData);
	console.log(title+": initial chart drawn");
	
	
	//When screen changes size, redraw chart to fit
	$(window).resize(function() {
				
				var phoneWidth = $(window).width();
				var phoneHeight = $(window).height();		
				
				drawChart(container, title, yAxisTitle, stepSize, chartLength, toolTitle, globalData);
				
	}); //  end of resize
	
	//One Year
	$(document).on('click', '#byr1', function() {
		
		stepSize = determineStepSize(density, 1);
		chartLength = determineChartLength(density, 1);
		
		drawChart(container, title, yAxisTitle, stepSize, chartLength, toolTitle, globalData);
	});
	
	//Five Year
	$(document).on('click', '#byr5', function() {
		
		stepSize = determineStepSize(density, 5);
		chartLength = determineChartLength(density, 5);
		
		drawChart(container, title, yAxisTitle, stepSize, chartLength, toolTitle, globalData);
	});
	
	//Ten Year
	$(document).on('click', '#byr10', function() {
		
		stepSize = determineStepSize(density, 10);
		chartLength = determineChartLength(density, 10);
		
		drawChart(container, title, yAxisTitle, stepSize, chartLength, toolTitle, globalData);
	});
}




//Function for retrieving data from database
function getData(url)
{
	var dataReturn;
	
	$.ajax({
     async: false,
     type: 'GET',
     url: url,
     success: function(data) {
		  dataReturn = data;
     }
	});	
	
	return dataReturn;
}


//All inclusive function for drawing a chart
function drawChart(container, chartTitle, yAxisTitle, stepSize, chartLength, toolTitle, globalData)
{
	$(document).ready(function() {
		
		console.log(chartTitle+": set options");
		var options = getChartOptions(container, chartTitle, yAxisTitle, stepSize);
		console.log(chartTitle+": done setting options");
		
		console.log(chartTitle+": render chart");
		renderChart(options, chartLength, toolTitle, globalData);
		console.log(chartTitle+": done render chart");		
	});
	
}


//Function for setting chart options
function getChartOptions(container, chartTitle, yAxisTitle, stepSize)
{	

	var options = {
		
		  chart: {
			  renderTo: container,
			  defaultSeriesType: 'line',
			  marginLeft: 50,							//	sets left margin was 50
			  marginRight: 30,	
			  //zoomType: 'x',
			  marginBottom: 50,
			  height: $(window).height()-20,
			  showAxes: true,
			  reflow: true,
		  },
		  plotOptions: {
			  line:{							// change to what ever the type is set to
			      marker: {
					  enabled: false			// gets ride of points on the line
						  }
				   }
		  },
		  title: {
			  text: chartTitle
		  },
		  tooltip: {
			  
			  useHTML: true,
			  formatter: function() {
				  var tooltipValue = (this.y)
				  
				  if(yAxisTitle === 'Price') {	// assigns $ symbol based on the name of y axis
					return ("<span class='highcharts-tooltip'><b>" + this.series.name + "</b></span>" + '<br/>' + this.x + ' <b>$' + Highcharts.numberFormat(this.y, 2) + '</b>')
				  }else{
					return ("<span class='highcharts-tooltip'><b>" + this.series.name + "</b></span>" + '<br/>' + this.x + ' <b>' + Highcharts.numberFormat(this.y, 2) + '</b>')  
				  } 
			  },
			  crosshairs: [true, true],
		  },
		  xAxis: {
			  type: 'datetime',
			  categories: [ ],
			  //gridLineWidth: 1,
				  labels: {
					  align: 'center',				//	aligns x axis labels to the left
					  rotation: 0,
					  step: stepSize,				// displayes every n'th tick label see global variable
					  y: 20,
					  //x: -10,	
					  
				  },
			  lineWidth: 2,
			  tickWidth: 0,							// removes yAxis ticks
		  },
		  yAxis: {
			  title: {
				  text: yAxisTitle,
				  x: 7,								//	moves text in x direction was 5
			  },
			  allowDecimals: false,				 
			  lineWidth: 2,							
													//  adds y axis line
			  labels: {								//	aligns x axis labels to the left
					  rotation: 0,
					  
					  x: -4,						//	shifts tick labels in x direction was -4
					  //step: 1,
					  
					  formatter: function(){
						  var absValue = Math.abs(this.value);
						  
					// Millions
						 if (absValue >= 100000000) {
							  absValue = (this.value / 1000000)
							  absValue = Highcharts.numberFormat(absValue, 0)
								return(absValue) + 'M'
						 }else if(absValue >= 10000000) {
							  absValue = (absValue / 1000000)
							  absValue = Highcharts.numberFormat(absValue, 1)
								return(absValue) + 'M'	
						 }else if(absValue >= 1000000) {
							  absValue = (absValue / 1000000)
							  absValue = Highcharts.numberFormat(absValue, 2)
							  	return(absValue) + 'M'	
					// Thousands			 
						 }else if(absValue >= 100000) {
							  absValue = (absValue / 1000)
							  absValue = Highcharts.numberFormat(absValue, 0)
								return(absValue) + 'k'	
						 }else if(absValue >= 10000) {
							  absValue = (absValue / 1000)
							  	/*if(yAxisTitle === '$USD') {	// assigns $ symbol based on the name of y axis
							  		absValue = Highcharts.numberFormat(absValue, 0)
							  		return'$' + (absValue) + 'k'	 
								}else{*/
									absValue = Highcharts.numberFormat(absValue, 1)
									return(absValue) + 'k'
								//}
								  
						 }else if(absValue >= 1000) {
							  absValue = (absValue / 1000)
							  absValue = Highcharts.numberFormat(absValue, 2)
							  	return(absValue) + 'k'   
								
					// Symbols based on Y axis label name	   
						  }else if(yAxisTitle === 'Percent') {	// assigns % symbol based on the name of y axis
						  	  absValue = Highcharts.numberFormat(absValue,1)
							  return(absValue) + '%'
						  }else if(yAxisTitle === 'Price') {	// assigns $ symbol based on the name of y axis
						  	  absValue = Highcharts.numberFormat(absValue,1)
							  return'$' + (absValue)
						  }else {
							  return this.value
						  };
						 
					  },
			  },
			  
			  gridLineWidth: 0,
		  },
		  exporting: {								// disables of the exporting button
			  buttons: {
				  contextButton: {
					  enabled: false,
				  },
			  },
		  },
		  legend:{
			  margin: 20,
			  enabled: false,						// disables legend box
		  },
		  series: [ ]
	};
	
	return options;
}


//Function for rendering a chart
function renderChart(options, chartLength, toolTitle, globalData)
{
	
	console.log("split globalData");
	lines = globalData.split("~");
	
   	$.each(lines, function(lineNo, line) {
	  console.log("split line:" + lineNo);
	  var items = line.split('=');
	  var chartMax = items.length;  
		
			
	   if (lineNo == 0) {
			$.each(items, function(columnNo, item) {
				if(columnNo > chartLength && columnNo < chartMax-1)
				{
					options.xAxis.categories.push(item);
				}
			});
		}  // end if statement
		else if (lineNo == 1){						// selects column by its number, or select all by using >= 0
			
			var series = {data: [ ]};
				$.each(items, function(rowNo, item) 
						{
							if (rowNo > chartLength && rowNo < chartMax-1) {
							series.data.push(parseFloat(item));	// parses a string and returns number as a number not a string
						};
				});//end of $.each
				series.name = toolTitle;					// adds name of the series
				options.series.push(series);
		}
	});	//end of $.each
	// Create the chart
	console.log("put data into chart");
	chart = new Highcharts.Chart(options);
	console.log("done putting data into chart");
}


//Removes inserted divs
function removeElements(page)
{
	//$('#container').remove();
	if(chart != undefined){chart.destroy()}
}



function determineStepSize(density, years)
{
	if(density == 'quarterly')
	{
		if(years == 10)
		{
			return 10;
		}
		else if(years == 5)
		{
			return 5;
		}
		else
		{
			return 1;
		}
	}
	else
	{
		
		if(years == 10)
		{
			return 40;
		}
		else if(years == 5)
		{
			return 20;
		}
		else
		{
			return 4;
		}
	}
		
}



function determineChartLength(density, years)
{
	if(density == 'quarterly')
	{
		if(years == 10)
		{
			return -1;
		}
		else if(years == 5)
		{
			return 19;
		}
		else
		{
			return 35;
		}
	}
	else
	{
		
		if(years == 10)
		{
			return -1;
		}
		else if(years == 5)
		{
			return 59;
		}
		else
		{
			return 107;
		}
	}
		
}





